/**
 * TO BE DETERMINED
 */
package org.eichar.client.shared;

/**
 * Represents a word with the string representation and its language. String
 * must be UTF-8
 * 
 * @author Jesse
 */
public class Word {
    private final String word;

    private final String language;

    protected Word(final String word, final String language) {
        super();
        this.word = word;
        this.language = language;
    }

    public String getLanguageCode() {
        return language;
    }

    public String getWord() {
        return word;
    }

    /**
     * @param string
     * @param string2
     * @return
     */
    public static Word get(String word, String language) {
        return new Word(word, language);
    }

    /**
     * @see java.lang.Object#hashCode()
     */
    /* @Override */
    public int hashCode() {
        final int PRIME = 31;
        int result = 1;
        result = PRIME * result
                + ((language == null) ? 0 : language.hashCode());
        result = PRIME * result + ((word == null) ? 0 : word.hashCode());
        return result;
    }

    /**
     * @see java.lang.Object#equals(java.lang.Object)
     */
    /* @Override */
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (!(obj instanceof Word))
            return false;
        final Word other = (Word) obj;
        if (language == null) {
            if (other.language != null)
                return false;
        } else if (!language.equals(other.language))
            return false;
        if (word == null) {
            if (other.word != null)
                return false;
        } else if (!word.equals(other.word))
            return false;
        return true;
    }

    /* @Override */
    public String toString() {
        StringBuffer builder = new StringBuffer();
        builder.append(word);
        builder.append(':');
        builder.append(language);
        return builder.toString();
    }

}
